#include "watchpoint.h"
#include "expr.h"
#include <stdlib.h>
// 监视点的池

#define NR_WP 32
static WP wp_pool[NR_WP];
static WP *head, *last, *free_;
void init_wp_pool()
{
	int i;
	for (i = 0; i < NR_WP; i++)
	{
		wp_pool[i].NO = i;
		wp_pool[i].next = &wp_pool[i + 1];
		wp_pool[i].expr = 0;
		// wp_pool[i].str = NULL;
	}
	wp_pool[NR_WP - 1].next = NULL;

	head = (WP *)malloc(sizeof(WP));
	head->NO = -1;
	head->next = NULL;
	head->expr = 0;
	// head->str = NULL;
	last = head;
	free_ = wp_pool;
}

WP *new_wp()
{
	last->next = free_;
	last = last->next;
	free_ = free_->next;
	last->next = NULL;
	if (free_ == NULL)
		assert(0);
	return last;
}

void free_wp(WP *wp)
{
	WP *temp = head;
	while (temp->next != wp)
	{
		temp = temp->next;
	}
	temp->next = wp->next;
	wp->next = free_;
	free_ = wp;
}

WP *returnhead()
{
	return head;
}
/* TODO: Implement the functionality of watchpoint */
